/**
 * Created by jinsebainian on 2017/9/22.
 */
var http = require('http'),
    url = require("url");
function start(route, handle) {
    function onRequest(request, response) {
        // 获取请求路径
        var pathname = url.parse(request.url).pathname;
        // 关闭nodejs 默认访问 favicon.ico
        if (!pathname.indexOf('/favicon.ico')) {
            return;
        };
        // 收到来自 pathname 的请求
        console.log("Request for " + pathname + " received.");
        // 路由器处理
        route(handle, pathname);

        // 返回数据
        response.writeHead(200, {"Content-type": "text/plain"});
        response.write("Hello world!");
        response.end();
    }

    http.createServer(onRequest).listen(8888);
    console.log("Server has start!");
}

// 开放接口
exports.start = start;